import config from '../config'

import { requestLocation } from '../service/location'

import util from "../utils";

export default {
    state: {
        test: {
            username: "test",
            password: "test"
        },
        number:0
    },
    reducers: {
        save(state, payload) {
            state.test.username = payload.username;
            state.test.password = payload.password;
            return state;
        },
        count(state,payload){
            state.number = state.number + 1;
            return state;
        }
    },

    effects: dispatch => {
        return {
            async getLocation(payload, rootState) {
                let result = await requestLocation();
                dispatch({
                    type: "common/save",
                    payload: {
                        city: result.city,
                        latitude: result.latitude,
                        longitude: result.longitude
                    }
                })
                return result;
            },
            async addAsync(payload, rootState) {
                new Promise(resolve => {
                    setTimeout(()=>{
                        console.log(dispatch);
                        dispatch.common.count()
                        resolve();
                    },1000)
                })
            },
        }
    }
}